
package com.example.paper.testFetchSize;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.paper.common.entity.UserStudent;
import com.example.paper.common.entity.UserStudent2;
import com.example.paper.common.mapper.UserStudentMapper;
import com.example.paper.common.mapper.UserStudent2Mapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * fetchSize使用示例
 */
@Slf4j
@Service
public class TestFetchSize implements ApplicationRunner {

    @Autowired
    private UserStudentMapper userStudentMapper;

    @Autowired
    private UserStudent2Mapper userStudent2Mapper;



    @Override
    public void run(ApplicationArguments args) throws Exception {
        // test();

    }

    private void test() {
        // userStudentMapper2.selectList方法 保持默认
        QueryWrapper<UserStudent2> queryWrapper2 = new QueryWrapper<>();
        List<UserStudent2> userStudents2 = userStudent2Mapper.selectList(queryWrapper2);
        log.info("selectList userStudents:{}", userStudents2.size());

        // userStudentMapper.selectList方法设置了fetchSize = 1000
        QueryWrapper<UserStudent> queryWrapper = new QueryWrapper<>();
        List<UserStudent> userStudents = userStudentMapper.selectList(queryWrapper);
        log.info("fetchSize selectList userStudents:{}", userStudents.size());
    }

}
